#案例：演示字典数据类型的一些小知识！

#如何定义一个字典：格式：字典名={k1:v1,k2:v2,.....}
a={}
b=dict()
c={"id":1}
d=\
{
    "id":1,
    "name":"张三",
    "score":78.5
}
e=\
{
    "id":1,
    "name":"张三",
    "score":78.5,
    "data1":{"my1":1,"my2":2},
    "data2":[1,2,3,4,5],
    "data3":[{"id":1,"name":"李四"},{"id":2,"name":"王五"}]
}

#如何获取字典中某元素的值:格式：字典名[Key]
a={"id":1,"name":"张三","age":27,"score":78.50}
name=a["name"]
print(name)

#如何修改字典中某元素的值:格式：字典名[Key]=新值
a={"id":1,"name":"张三","age":27,"score":78.50}
a["name"]="张三三"
print(a)

#如何为新增一个新元素:格式：字典名[新Key]=新值
a={"id":1,"name":"张三","age":27,"score":78.50}
a["addr"]="深圳市龙华区"
print(a)


#删除字典
#情况1：删除字典中某元素：格式：del 字典名[Key]
a={"id":1,"name":"张三","age":27,"score":78.50}
del a["name"]
print(a)

#情况2：删除整个字典:格式：del 字典名
a={"id":1,"name":"张三","age":27,"score":78.50}
del a


#情况3：清空某字典:a.clear()
a={"id":1,"name":"张三","age":27,"score":78.50}
a.clear() #a={}
print(a)

